## Replication: "Backscratching in Banks: Political Cycles in Bank Manager Appointments."
## Robustness Analyses (in chronological order as appearing in appendix):
### -- replication code for all empirical analyses and plots in the online appendix of the paper
## R Version: 3.6.0 (2019-04-26)
## platform:  x86_64-apple-darwin15.6.0
#######################################

rm(list = ls())

# load packages
library(eha)
require(devtools)
library(survival)
library(flexsurv)
library(stargazer)
library(texreg)  
library(dplyr)
library(simPH)
library(lfe)

# set working directory
## -- set your working directory --

# load data
cajas.boards <- read.table(file = "cajas_dta.txt", header = T
  , stringsAsFactors = F)  # data for Spanish savings banks
cbanks.election <- read.table(file = "commercial-banks_dta.txt", header = T
  , stringsAsFactors = F)  # data for Spanish commercial banks


set.seed(123)

###############################################################################
############## APPENDIX #######################################################
###############################################################################

# **Table A3: Summary Statistics**:  ------------------------------------------

## generate dummies for different parties
cajas.boards$social <- ifelse(cajas.boards$region.govParty == "Socialist", 1, 0)
cajas.boards$conserv <- ifelse(cajas.boards$region.govParty == "Conservative", 1, 0)
cajas.boards$other <- ifelse(cajas.boards$region.govParty == "Others", 1, 0)

## obtain summary statistics
stargazer(as.data.frame(cajas.boards[cajas.boards$bank.chair == 1
  ,c("region.postElec"
    ,"region.govChange"
    , "region.yrsInGov"
    , "region.coal"
    , "bank.roaLag1"
    , "conserv"
    , "social"
    , "other"
    , "bank.polVote")])
  , title = "Summary Statistics"
  , label = "T:sumstat", digits = 2
  , omit.summary.stat = c("p25", "p75")
  , covariate.labels = c("Post Election"
    ,"Government Change"
    , "Years in Government"
    , "Coalition"
    , "Return on Assets"
    , "Party: Conservative"
    , "Party: Socialist"
    , "Party: Other"
    , "Public Sector Vote Share")
  , type = "text")

## get summary statistics for tenure (manual estimation of last two rows of table)
round(summary(cajas.boards[cajas.boards$bank.chair ==1,]$bank.yrsInOffice), 2)
round(sd(cajas.boards[cajas.boards$bank.chair ==1,]$bank.yrsInOffice), 2)
round(summary(cajas.boards[cajas.boards$bank.chair ==0,]$bank.yrsInOffice), 2)
round(sd(cajas.boards[cajas.boards$bank.chair ==0,]$bank.yrsInOffice), 2)

# **Table A4**: Test of PH Assumption:  ---------------------------------------


## function for cox.zph to test proportionality of hazards

cox.zphFunc <- function (fit, transform = "km", global = TRUE) 
{
  call <- match.call()
  if (!inherits(fit, "coxph")) 
    stop("Argument must be the result of coxph")
  if (inherits(fit, "coxph.null")) 
    stop("The are no score residuals for a Null model")
  sresid <- resid(fit, "schoenfeld")
  varnames <- names(fit$coefficients)
  nvar <- length(varnames)
  ndead <- length(sresid)/nvar
  if (nvar == 1) 
    times <- as.numeric(names(sresid))
  else times <- as.numeric(dimnames(sresid)[[1]])
  if (is.character(transform)) {
    tname <- transform
    ttimes <- switch(transform, identity = times, rank = rank(times), 
      log = log(times), km = {
        temp <- survfitKM(factor(rep(1, nrow(fit$y))), 
          fit$y, se.fit = FALSE)
        t1 <- temp$surv[temp$n.event > 0]
        t2 <- temp$n.event[temp$n.event > 0]
        km <- rep(c(1, t1), c(t2, 0))
        if (is.null(attr(sresid, "strata"))) 1 - km else (1 - 
            km[sort.list(sort.list(times))])
      }, stop("Unrecognized transform"))
  }
  else {
    tname <- deparse(substitute(transform))
    if (length(tname) > 1) 
      tname <- "user"
    ttimes <- transform(times)
  }
  xx <- ttimes - mean(ttimes)
  r2 <- sresid %*% fit$var * ndead
  test <- xx %*% r2
  corel <- c(cor(xx, r2))
  z <- c(test^2/(diag(fit$var) * ndead * sum(xx^2)))
  Z.ph <- cbind(corel, z, pchisq(z, 1, lower.tail = FALSE))
  if (global && nvar > 1) {
    test <- c(xx %*% sresid)
    z <- c(test %*% fit$var %*% test) * ndead/sum(xx^2)
    Z.ph <- rbind(Z.ph, c(NA, z, pchisq(z, ncol(sresid), 
      lower.tail = FALSE)))
    dimnames(Z.ph) <- list(c(varnames, "GLOBAL"), c("rho", 
      "chisq", "p"))
  }
  else dimnames(Z.ph) <- list(varnames, c("rho", "chisq", "p"))
  dimnames(r2) <- list(times, names(fit$coefficients))
  temp <- list(table = Z.ph, x = ttimes, y = r2 + outer(rep(1, 
    ndead), fit$coefficients), var = fit$var, call = call, 
    transform = tname)
  if (is.R()) 
    class(temp) <- "cox.zph"
  else oldClass(temp) <- "cox.zph"
  temp
}

## Uncorrected Cox Model w/out Time and Frailties
fit.basic <- coxph(Surv(bank.yrsInOffice, bank.event) ~  region.yrsInGov +
    region.postElec +
    region.coal + 
    bank.polVote +
    bank.roaLag1 +
    as.factor(region.govParty)  +
    frailty(bank.id, distribution = "gaussian"),
  data = cajas.boards)

## Grambsch-Thernau and Harroll's rho test for basic model
### this table appears as Table A4 in the appendix.
phtest.basic <- cox.zphFunc(fit.basic)
print(phtest.basic)

### estimates differ slightly from the submitted manuscript
### substantive conclusions are not affected
### this was discussed and accepted by the editor

## account for violation by interacting with measure of time
fit.corrected <- coxph(Surv(bank.yrsInOffice, bank.event) ~ region.yrsInGov +
    region.postElec +
    region.coal + 
    bank.polVote +
    bank.roaLag1 +
    as.factor(region.govParty) + as.factor(region.govParty):bank.yrsInOffice  +
    frailty(bank.id, distribution = "gaussian"),
  method = "efron",
  data = cajas.boards)

## Grambsch-Thernau and Harroll's rho test for corrected model
phtest <- cox.zphFunc(fit.corrected)
print(phtest)

# Table A5: exclude early/repeated elections ----------------------------------

## exclude early and repeated elections (identified separately, see footnote 12 in Appendix)
cajas.boards.rstrct <- subset(cajas.boards,
  !(cajas.boards$region.id == 13 & cajas.boards$year >= 2003 & cajas.boards$year < 2007) 
  & !(cajas.boards$region.id == 9 & cajas.boards$year >= 1995 & cajas.boards$year < 1999)
  & !(cajas.boards$region.id == 9 & cajas.boards$year >= 2006 & cajas.boards$year < 2010)
  & !(cajas.boards$region.id == 16 & cajas.boards$year >= 1986 & cajas.boards$year < 1990)
  & !(cajas.boards$region.id == 16 & cajas.boards$year >= 2001 & cajas.boards$year < 2005)
  & !(cajas.boards$region.id == 1 & cajas.boards$year >= 1996 & cajas.boards$year < 2000))

## Column 1
fit0.earlyElec <- coxph(Surv(bank.yrsInOffice, bank.event) ~  region.yrsInGov,
  method = "efron",
  data = cajas.boards.rstrct, subset = bank.chair == 1)
summary(fit0.earlyElec)

## Column 2
fit1.earlyElec <- coxph(Surv(bank.yrsInOffice, bank.event) ~  region.yrsInGov +
    region.coal + 
    bank.polVote +
    bank.roaLag1 +
    as.factor(region.govParty) + as.factor(region.govParty):bank.yrsInOffice +
    frailty(bank.id, distribution = "gaussian"),
  method = "efron",
  data = cajas.boards.rstrct, subset = bank.chair == 1)
summary(fit1.earlyElec)

## Column 3
fit2.earlyElec <- coxph(Surv(bank.yrsInOffice, bank.event) ~ region.yrsInGov +
    region.coal + 
    region.postElec +
    bank.polVote +
    bank.roaLag1 +
    as.factor(region.govParty) + as.factor(region.govParty):bank.yrsInOffice +
    frailty(bank.id, distribution = "gaussian"),
  method = "efron",
  data = cajas.boards.rstrct, subset = bank.chair == 1)
summary(fit2.earlyElec)

screenreg(list(fit0.earlyElec, fit1.earlyElec,fit2.earlyElec),
  caption = "Cox PH Model excluding irregular elections", caption.above = T,
  label="T:exclIrregElec",
  custom.coef.names = c("Years in Government"
    , "Coalition"
    , "Public Sector Vote Share"
    , "Return on Assets$_{t-1}$"
    , "Party: Other", "Party: Socialist", "Post Election"),
  custom.model.names = c("Raw Model", "Full Model 1", "Full Model 2"),
  include.rsquared=F, include.maxrs=F, include.missings=F, include.zph=F,
  reorder.coef = c(1:2,7,3:6),
  stars = c(.01,.05,.1),
  omit.coef = c("bank.yrsInOffice"))

### estimates in model 2 differ slightly from the submitted manuscript
### substantive conclusions are not affected
### this was discussed and accepted by the editor


# **Table A6**: CEO only ------------------------------------------------------

## Column 1
fit.ceoMod1 <- coxph(Surv(bank.yrsInOffice, bank.event) ~  region.yrsInGov +
    region.coal + 
    bank.polVote +
    bank.roaLag1 +
    as.factor(region.govParty) + as.factor(region.govParty):bank.yrsInOffice +
    frailty(bank.id, distribution = "gaussian"),
  method = "efron",
  data = cajas.boards, subset = bank.chair == 0)
summary(fit.ceoMod1)

## Column 2
fit.ceoMod2 <- coxph(Surv(bank.yrsInOffice, bank.event) ~ region.yrsInGov +
    region.coal + 
    region.postElec +
    bank.polVote +
    bank.roaLag1 +
    as.factor(region.govParty) + as.factor(region.govParty):bank.yrsInOffice +
    frailty(bank.id, distribution = "gaussian"),
  method = "efron",
  data = cajas.boards, subset = bank.chair == 0)
summary(fit.ceoMod2)

## Column 3
fit.ceoMod3a <- coxph(Surv(bank.yrsInOffice, bank.event) ~ region.coal + 
    region.postElec +
    region.coal:region.postElec +
    bank.polVote +
    bank.roaLag1 +
    as.factor(region.govParty) + as.factor(region.govParty):bank.yrsInOffice +
    frailty(bank.id, distribution = "gaussian"),
  method = "efron",
  data = cajas.boards, subset = bank.chair == 0 & region.govChange == 1)
summary(fit.ceoMod3a)

## Column 4
fit.ceoMod3b <- coxph(Surv(bank.yrsInOffice, bank.event) ~ region.coal + 
    region.postElec +
    region.coal:region.postElec +
    bank.polVote +
    bank.roaLag1 +
    as.factor(region.govParty) + as.factor(region.govParty):bank.yrsInOffice +
    frailty(bank.id, distribution = "gaussian"),
  method = "efron",
  data = cajas.boards, subset = bank.chair == 0 & region.govChange == 0)
summary(fit.ceoMod3b)

screenreg(list(fit.ceoMod1, fit.ceoMod2, fit.ceoMod3a, fit.ceoMod3b),
  caption = "Cox PH Model, Bank CEOs Only", caption.above = T,
  label="T:findingsCeo",
  custom.coef.names = c("Years in Government"
    , "Coalition"
    , "Public Sector Vote Share"
    , "Return on Assets$_{t-1}$"
    , "Party: Other", "Party: Socialist"
    , "Post Election"
    , "Post Election * Coalition"),
  custom.model.names = c("Full Model 1", "Full Model 2", "After Gov't Change", "No Gov't Change"),
  include.rsquared=F, include.maxrs=F, include.missings=F, include.zph=F,
  reorder.coef = c(1:2,7:8,3:6),
  stars = c(.01,.05,.1),
  omit.coef = c("bank.yrsInOffice"))

### estimates in model 2 differ slightly from the submitted manuscript
### substantive conclusions are not affected
### this was discussed and accepted by the editor

# **Table A7**: federal elections ---------------------------------------------

## Column 1
fit.FedChair <- coxph(Surv(bank.yrsInOffice, bank.event) ~ fed.yrsInGov + 
    fed.postElec + 
    bank.polVote +
    bank.roaLag1 +
    as.factor(fed.govParty) +  as.factor(fed.govParty):bank.yrsInOffice +
    frailty(bank.id, distribution = "gaussian"),
  method = "efron",
  data = cajas.boards, subset = bank.chair == 1)
summary(fit.FedChair)

## Column 2
fit.FedCEO <- coxph(Surv(bank.yrsInOffice, bank.event) ~ fed.yrsInGov + 
    fed.postElec + 
    bank.polVote +
    bank.roaLag1 +
    as.factor(fed.govParty) + as.factor(fed.govParty):bank.yrsInOffice +
    frailty(bank.id, distribution = "gaussian"),
  method = "efron",
  data = cajas.boards, subset = bank.chair == 0)
summary(fit.FedCEO)

texreg(list(fit.FedChair, fit.FedCEO),
  caption = "Placebo Test using Federal Elections", caption.above = T,
  label="T:placebo",
  custom.coef.names = c("Years in Government"
    , "Post General Election"
    , "Public Sector Vote Share"
    , "Return on Assets$_{t-1}$"
    , "Party: Socialist"),
  custom.model.names = c("Chairpersons", "CEOs"),
  include.rsquared=F, include.maxrs=F, include.missings=F, include.zph=F,
  stars = c(.01,.05,.1),
  omit.coef = c("bank.yrsInOffice"))

### estimates in model 2 differ slightly from the submitted manuscript
### substantive conclusions are not affected
### this was discussed and accepted by the editor

# **Table A8**: Placebo Test using commercial banks ---------------------------

## Column 1
fit.cbanksMod1 <- coxph(Surv(bank.yrsInOffice, bank.event) ~  region.yrsInGov,
  method = "efron",
  data = cbanks.election, subset = bank.chair == 1)
summary(fit.cbanksMod1)

## Column 2
fit.cbanksMod2 <- coxph(Surv(bank.yrsInOffice, bank.event) ~  region.yrsInGov +
    region.coal + 
    bank.roaLag1 +
    as.factor(region.govParty) + as.factor(region.govParty):bank.yrsInOffice +
    frailty(bank.id, distribution = "gaussian"),
  method = "efron",
  data = cbanks.election, subset = bank.chair == 1)
summary(fit.cbanksMod2)

## Column 3
fit.cbanksMod3 <- coxph(Surv(bank.yrsInOffice, bank.event) ~ region.yrsInGov +
    region.coal + 
    region.postElec + 
    bank.roaLag1 +
    as.factor(region.govParty) + as.factor(region.govParty):bank.yrsInOffice +
    frailty(bank.id, distribution = "gaussian"),
  method = "efron",
  data = cbanks.election, subset = bank.chair == 1)
summary(fit.cbanksMod3)

screenreg(list(fit.cbanksMod1, fit.cbanksMod2, fit.cbanksMod3),
  caption = "Cox PH Model using 16 commercial banks as a placebo", caption.above = T,
  custom.coef.names = c("Years in Government"
    , "Coalition"
    , "Return on Assets$_{t-1}$"
    , "Party: Other", "Party: Socialist"
    , "Post Election"),
  custom.model.names = c("Raw Model", "Full Model 1", "Full Model 2"),
  include.rsquared=F, include.maxrs=F, include.missings=F, include.zph=F,
  stars = c(.01,.05,.1),
  reorder.coef = c(1,6,2:5),
  omit.coef = c("bank.yrsInOffice"))

# **Table A9**: FE models w/ region and year Fixed Effects --------------------

## Column 1
fit.fe0 <- felm(bank.event ~ region.yrsInGov +
    region.coal + 
    region.postElec +
    bank.polVote +
    bank.roaLag1 +
    as.factor(region.govParty) | 0 | 0 | 0
  , data = cajas.boards, subset = bank.chair == 1, exactDOF=TRUE)
summary(fit.fe0)

## Column 2
fit.fe1 <- felm(bank.event ~ region.yrsInGov +
    region.coal + 
    region.postElec +
    bank.polVote +
    bank.roaLag1 +
    as.factor(region.govParty) | region.id | 0 | region.id
  , data = cajas.boards, subset = bank.chair == 1, exactDOF=TRUE)
summary(fit.fe1)

## Column 3
fit.fe2 <- felm(bank.event ~ region.yrsInGov +
    region.coal +
    region.postElec +
    bank.polVote +
    bank.roaLag1 +
    as.factor(region.govParty) | year | 0 | region.id
  , data = cajas.boards, subset = bank.chair == 1, exactDOF=TRUE)
summary(fit.fe2)

## Column 4
fit.fe3 <- felm(bank.event ~ region.yrsInGov
  | year + region.id | 0 | region.id
  , data = cajas.boards, subset = bank.chair == 1, exactDOF=TRUE)
summary(fit.fe3)

## Column 5
fit.fe4 <- felm(bank.event ~ region.yrsInGov +
    region.coal + 
    region.postElec +
    bank.polVote +
    bank.roaLag1 +
    as.factor(region.govParty) | year + region.id | 0 | region.id
  , data = cajas.boards, subset = bank.chair == 1, exactDOF=TRUE)
summary(fit.fe4)

## Column 6
fit.fe5 <- felm(bank.event ~ region.yrsInGov
  | year + region.id | 0 | region.id
  , data = cajas.boards, subset = bank.chair == 1 & bank.mergerSubject != 1
  , exactDOF=TRUE)
summary(fit.fe5)

## Column 7
fit.fe6 <- felm(bank.event ~ region.yrsInGov +
    region.coal + 
    region.postElec +
    bank.polVote +
    bank.roaLag1 +
    as.factor(region.govParty) | year + region.id | 0 | region.id
  , data = cajas.boards, subset = bank.chair == 1 & bank.mergerSubject != 1
  , exactDOF=TRUE)
summary(fit.fe6)

stargazer(fit.fe0, fit.fe1, fit.fe2, fit.fe3, fit.fe4, fit.fe5, fit.fe6
  , title = "Fixed Effect Models"
  , omit = "Constant"
  , covariate.labels = c("Years in Government"
    , "Coalition"
    , "Post Election"
    , "Public Sector Vote Share"
    , "Return on Assets$_{t-1}$"
    , "Party: Other", "Party: Socialist")
  , digits = 2, omit.stat = c("ser", "adj.rsq", "rsq")
  , dep.var.caption = "", dep.var.labels = ""
  , column.labels = c("Naive Model", "Region FE", "Time FE", "Region + Time FE", "Region + Time FE", "Region + Time FE", "Region + Time FE")
  , add.lines = list(c("Region FE", "no", "yes", "no", "yes", "yes", "yes", "yes"),
    c("Year FE", "no", "no", "yes", "yes", "yes", "yes", "yes"))
  , type = "text")

### number of observations in models 4 and 6 differ slightly from the submitted manuscript
### substantive conclusions are not affected
### this was discussed and accepted by the editor

# **Table A10**: Explaining mergers in Spanish savings banks ------------------

## Column 1
fit.feMerger <- felm(bank.mergerSubject ~ region.yrsInGov +
    region.coal + 
    region.postElec +
    bank.polVote +
    bank.roaLag1 +
    as.factor(region.govParty) | year + region.id | 0 | region.id
  , data = cajas.boards, subset = bank.chair == 1, exactDOF=TRUE)
summary(fit.feMerger)

stargazer(fit.feMerger
  , title = "Explaining mergers in Spanish savings banks", label="T:fe.merger"
  , omit = "Constant"
  , covariate.labels = c("Years in Government"
    , "Coalition"
    , "Post Election"
    , "Public Sector Vote Share"
    , "Return on Assets$_{t-1}$"
    , "Party: Other", "Party: Socialist")
  , digits = 2, omit.stat = c("ser", "adj.rsq", "rsq")
  , dep.var.caption = "", dep.var.labels = "Bank Merger"
  , type = "text")

# **Table A11**: Robustness to different merger codings -----------------------

## Column 1: all merged as right-censored
fit.allCnsr <- coxph(Surv(bank.yrsInOffice, bank.mergerAllCnsr) ~ region.yrsInGov + 
    region.coal + 
    region.postElec + 
    bank.polVote +
    bank.roaLag1 +
    as.factor(region.govParty) + as.factor(region.govParty):bank.yrsInOffice +
    frailty(bank.id, distribution = "gaussian"),
  method = "efron",
  data = cajas.boards, subset = bank.chair == 1)
summary(fit.allCnsr)

## Column 2: all merged as 'event'
fit.allEvnt <- coxph(Surv(bank.yrsInOffice, bank.mergerAllEvent) ~ region.yrsInGov + 
    region.coal + 
    region.postElec + 
    bank.polVote +
    bank.roaLag1 +
    as.factor(region.govParty) + as.factor(region.govParty):bank.yrsInOffice +
    frailty(bank.id, distribution = "gaussian"),
  method = "efron",
  data = cajas.boards, subset = bank.chair == 1)
summary(fit.allEvnt)

## Column 3: only banks never involved in merger
fit.noMerger <- coxph(Surv(bank.yrsInOffice, bank.event) ~ region.yrsInGov + 
    region.coal + 
    region.postElec + 
    bank.polVote +
    bank.roaLag1 +
    as.factor(region.govParty) + as.factor(region.govParty):bank.yrsInOffice +
    frailty(bank.id, distribution = "gaussian"),
  method = "efron",
  data = cajas.boards, subset = bank.chair == 1 & bank.mergerSubject == 0 & bank.mergerResult == 0)
summary(fit.noMerger)

screenreg(list(fit.allCnsr, fit.allEvnt, fit.noMerger),
  caption = "Robustness of findings to different codings of bank mergers"
  , caption.above = T,
  custom.coef.names = c("Years in Government"
    , "Coalition"
    , "Post Election"
    , "Public Sector Vote Share"
    , "Return on Assets$_{t-1}$"
    , "Party: Other", "Party: Socialist"),
  include.rsquared=F, include.maxrs=F, include.missings=F, include.zph=F,
  custom.model.names = c("All right-censored", "All event", "Banks never involved in merger"),
  reorder.coef = c(1, 3, 2, 4:7),
  stars = c(.01,.05,.1),
  omit.coef = c("bank.yrsInOffice"))

# **Table A12**: restricted time window ---------------------------------------

## Column 1
fit.post1990 <- coxph(Surv(bank.yrsInOffice, bank.event) ~ region.yrsInGov + 
    region.coal + 
    region.postElec + 
    bank.polVote +
    bank.roaLag1 +
    as.factor(region.govParty) + as.factor(region.govParty):bank.yrsInOffice +
    frailty(bank.id, distribution = "gaussian"),
  method = "efron",
  data = cajas.boards, subset = bank.chair == 1 & year >= 1990)
summary(fit.post1990)

## Column 2
fit.pre2008 <- coxph(Surv(bank.yrsInOffice, bank.event) ~ region.yrsInGov + 
    region.coal + 
    region.postElec + 
    bank.polVote +
    bank.roaLag1 +
    as.factor(region.govParty) + as.factor(region.govParty):bank.yrsInOffice +
    frailty(bank.id, distribution = "gaussian"),
  method = "efron",
  data = cajas.boards, subset = bank.chair == 1 & year < 2008)
summary(fit.pre2008)

## Column 3
fit.post1990pre2008 <- coxph(Surv(bank.yrsInOffice, bank.event) ~ region.yrsInGov + 
    region.coal + 
    region.postElec + 
    bank.polVote +
    bank.roaLag1 +
    as.factor(region.govParty) + as.factor(region.govParty):bank.yrsInOffice +
    frailty(bank.id, distribution = "gaussian"),
  method = "efron",
  data = cajas.boards, subset = bank.chair == 1 & year >= 1990 & year < 2008)
summary(fit.post1990pre2008)

screenreg(list(fit.post1990, fit.pre2008, fit.post1990pre2008),
  caption = "Cox PH model with subsample for observations between 1990–2007", 
  caption.above = T,
  custom.coef.names = c("Years in Government"
    , "Coalition"
    , "Post Election"
    , "Public Sector Vote Share"
    , "Return on Assets$_{t-1}$"
    , "Party: Other", "Party: Socialist"),
  include.rsquared=F, include.maxrs=F, include.missings=F, include.zph=F,
  custom.model.names = c("excl. pre-1990", "excl. post-2007", "1990-2007"),
  reorder.coef = c(1, 3, 2, 4:7),
  stars = c(.01,.05,.1),
  omit.coef = c("bank.yrsInOffice"))

### **Table A13**: hazard over cycle ------------------------------------------

## Column 1
fit.cycle <- coxph(Surv(bank.yrsInOffice, bank.event) ~ factor(region.elecCycle) +
    region.yrsInGov +
    region.coal + 
    bank.polVote +
    bank.roaLag1 +
    as.factor(region.govParty) + as.factor(region.govParty):bank.yrsInOffice +
    frailty(bank.id, distribution = "gaussian"),
  method = "efron",
  data = cajas.boards, subset = bank.chair == 1)
summary(fit.cycle)

screenreg(list(fit.cycle),
  caption = "Alternative specification of election variable", caption.above = T,
  custom.coef.names = c("Election$_{t+1}$"
    , "Election$_{t+2}$"
    , "Election$_{t+3}$"
    , "Years in Government"
    , "Coalition"
    , "Public Sector Vote Share"
    , "Return on Assets$_{t-1}$"
    , "Party: Other", "Party: Socialist"),
  include.rsquared=F, include.maxrs=F, include.missings=F, include.zph=F,
  stars = c(.01,.05,.1),
  omit.coef = c("bank.yrsInOffice"))

# **Table A14**: interaction / pol vote share ---------------------------------

## Column 1
fit.interact1 <- coxph(Surv(bank.yrsInOffice, bank.event) ~ region.yrsInGov +
    region.postElec * bank.polVote + 
    region.coal +
    bank.roaLag1 +
    as.factor(region.govParty) + as.factor(region.govParty):bank.yrsInOffice +
    frailty(bank.id, distribution = "gaussian"),
  method = "efron",
  data = cajas.boards, subset = bank.chair == 1)
summary(fit.interact1)

## Column 2
fit.interact2 <- coxph(Surv(bank.yrsInOffice, bank.event) ~ region.postElec * bank.polVote + 
    region.coal +
    bank.roaLag1 +
    as.factor(region.govParty) + as.factor(region.govParty):bank.yrsInOffice +
    frailty(bank.id, distribution = "gaussian"),
  method = "efron",
  data = cajas.boards, subset = bank.chair == 1 & region.govChange == 1)
summary(fit.interact2)

## Column 3
fit.interact3 <- coxph(Surv(bank.yrsInOffice, bank.event) ~ region.postElec * bank.polVote + 
    region.coal +
    bank.roaLag1 +
    as.factor(region.govParty) + as.factor(region.govParty):bank.yrsInOffice +
    frailty(bank.id, distribution = "gaussian"),
  method = "efron",
  data = cajas.boards, subset = bank.chair == 1 & region.govChange == 0)
summary(fit.interact3)

screenreg(list(fit.interact1, fit.interact2, fit.interact3),
  caption = "Cox PH Model exploring effect heterogeneity for public sector vote share", 
  caption.above = T,
  custom.coef.names = c("Years in Government"
    , "Post Election"
    , "Public Sector Vote Share"
    , "Coalition"
    , "Return on Assets$_{t-1}$"
    , "Party: Other", "Party: Socialist", "Post Election * Public Sector Vote Share"),
  include.rsquared=F, include.maxrs=F, include.missings=F, include.zph=F,
  reorder.coef = c(1:3,8,4:7),
  stars = c(.01,.05,.1),
  omit.coef = c("bank.yrsInOffice"))


# **Table A15**: effect by bank size ------------------------------------------

## generate year-specific asset quartiles
cajas.boards <- cajas.boards[cajas.boards$bank.chair == 1,] %>%
  group_by(year) %>%
  mutate(m.assets = mean(bank.assetsTot, na.rm = T)
    , qrt.assets = ntile(bank.assetsTot, 4))

## Column 1 - quartile 1
fit.qrt1 <- coxph(Surv(bank.yrsInOffice, bank.event) ~ region.yrsInGov + 
    region.coal + 
    region.postElec +
    bank.polVote +
    bank.roaLag1 +
    as.factor(region.govParty) + as.factor(region.govParty):bank.yrsInOffice +
    frailty(bank.id, distribution = "gaussian"),
  method = "efron",
  data = cajas.boards, subset = bank.chair == 1 & qrt.assets == 1)
summary(fit.qrt1)

## Column 2 - quartile 1
fit.qrt2 <- coxph(Surv(bank.yrsInOffice, bank.event) ~ region.yrsInGov + 
    region.coal + 
    region.postElec +
    bank.polVote +
    bank.roaLag1 +
    as.factor(region.govParty) + as.factor(region.govParty):bank.yrsInOffice +
    frailty(bank.id, distribution = "gaussian"),
  method = "efron",
  data = cajas.boards, subset = bank.chair == 1 & qrt.assets == 2)
summary(fit.qrt2)

## Column 3 - quartile 3
fit.qrt3 <- coxph(Surv(bank.yrsInOffice, bank.event) ~ region.yrsInGov + 
    region.coal + 
    region.postElec +
    bank.polVote +
    bank.roaLag1 +
    as.factor(region.govParty) + as.factor(region.govParty):bank.yrsInOffice +
    frailty(bank.id, distribution = "gaussian"),
  method = "efron",
  data = cajas.boards, subset = bank.chair == 1 & qrt.assets == 3)
summary(fit.qrt3)

## Column 4 - quartile 4
fit.qrt4 <- coxph(Surv(bank.yrsInOffice, bank.event) ~ region.yrsInGov + 
    region.coal + 
    region.postElec +
    bank.polVote +
    bank.roaLag1 +
    as.factor(region.govParty) + as.factor(region.govParty):bank.yrsInOffice +
    frailty(bank.id, distribution = "gaussian"),
  method = "efron",
  data = cajas.boards, subset = bank.chair == 1 & qrt.assets == 4)
summary(fit.qrt4)

screenreg(list(fit.qrt1, fit.qrt2, fit.qrt3, fit.qrt4),
  caption = "Cox PH Model, splitting sample by bank size", caption.above = T,
  custom.coef.names = c("Years in Government"
    , "Coalition"
    , "Post Election"
    , "Public Sector Vote Share"
    , "Return on Assets$_{t-1}$"
    , "Party: Other", "Party: Socialist"),
  custom.model.names = c("Quartile 1", "Quartile 2", "Quartile 3", "Quartile 4"),
  include.rsquared=F, include.maxrs=F, include.missings=F, include.zph=F,
  stars = c(.01,.05,.1),
  omit.coef = c("bank.yrsInOffice"))

### estimates and number of observations in model 2-3 differ slightly from the submitted manuscript
### substantive conclusions are not affected
### this was discussed and accepted by the editor

# **Table A16**: polynomials for "Years in Government" ------------------------

## Column 1 - main specification from manuscript (Table 1, Model 3)
fit.main3 <- coxph(Surv(bank.yrsInOffice, bank.event) ~ region.yrsInGov +
    region.postElec +
    region.coal + 
    bank.polVote +
    bank.roaLag1 +
    as.factor(region.govParty) + as.factor(region.govParty):bank.yrsInOffice +
    frailty(bank.id, distribution = "gaussian"),
  method = "efron",
  data = cajas.boards, subset = bank.chair == 1)
summary(fit.main3)

## Column 2 - quadratic
fit.quadratic <- coxph(Surv(bank.yrsInOffice, bank.event) ~ region.yrsInGov + I(region.yrsInGov^2) +
    region.coal + 
    region.postElec +
    bank.polVote +
    bank.roaLag1 +
    as.factor(region.govParty) + as.factor(region.govParty):bank.yrsInOffice +
    frailty(bank.id, distribution = "gaussian"),
  method = "efron",
  data = cajas.boards, subset = bank.chair == 1)
summary(fit.quadratic)  # loglik = 814.8

## Column 3 - cubic
fit.cubic <- coxph(Surv(bank.yrsInOffice, bank.event) ~ region.yrsInGov + I(region.yrsInGov^2) + I(region.yrsInGov^3) +
    region.coal + 
    region.postElec +
    bank.polVote +
    bank.roaLag1 +
    as.factor(region.govParty) + as.factor(region.govParty):bank.yrsInOffice +
    frailty(bank.id, distribution = "gaussian"),
  method = "efron",
  data = cajas.boards, subset = bank.chair == 1)
summary(fit.cubic) # loglik = 815

screenreg(list(fit.main3, fit.quadratic, fit.cubic),
  caption = "Cox PH Model, different polynomials for Years in Government", 
  caption.above = T,
  custom.coef.names = c("Years in Government"
    , "Post Election"
    , "Coalition"
    , "Public Sector Vote Share"
    , "Return on Assets$_{t-1}$"
    , "Party: Other", "Party: Socialist"
    , "Years in Government^2", "Years in Government^3"),
  reorder.coef = c(1, 8:9, 3, 2, 4:7),
  custom.model.names = c("Linear", "Quadratic", "Cubic"),
  include.rsquared=T, include.maxrs=T, include.loglik = T, 
  include.missings=F, include.zph=F,
  stars = c(.01,.05,.1),
  omit.coef = c("bank.yrsInOffice"))

# **Figure 3**: plot different polynomials -----------------------------------

## simulate values from Table A16, Column 1 using 'simPH' package
plot.region.yrsInGov <- coxsimLinear(fit.main3
  , b = "region.yrsInGov"
  , Xj = seq(1, 28, by = 1)) # for year 1--28

## simulate values from Table A16, Column 2 using 'simPH' package
plot.quadratic <- coxsimPoly(fit.quadratic, b = "region.yrsInGov", 
  pow = 2, Xj = seq(1, 28, by = 1))

## simulate values from Table A16, Column 3 using 'simPH' package
plot.cubic <- coxsimPoly(fit.cubic, b = "region.yrsInGov", 
  pow = 3, Xj = seq(1, 28, by = 1))

## plot left-hand figure in Figure 3
pdf("figures/effect_govChangeYr.pdf") 
simGG(plot.region.yrsInGov
  , xlab = "Years in Government"
  , lcolour = "black"
  , pcolour = "grey"
  , alpha = .5
  , type = "points")
dev.off()

## plot middle figure in Figure 3
pdf("figures/effect_quadratic.pdf") 
simGG(plot.quadratic
  , xlab = "Years in Government"
  , lcolour = "black"
  , pcolour = "grey"
  , alpha = .5
  , type = "points")
dev.off()

## plot right-hand figure in Figure 3
pdf("figures/effect_cubic.pdf") 
simGG(plot.cubic
  , xlab = "Years in Government"
  , lcolour = "black"
  , pcolour = "grey"
  , alpha = .5
  , type = "points")
dev.off()

# **Table A17**: Unseated coalition governments -------------------------------

## Column 1
fit.coal1 <- coxph(Surv(bank.yrsInOffice, bank.event) ~  region.coalBefore +
    region.postElec +
    bank.polVote +
    bank.roaLag1 +
    as.factor(region.govParty) + as.factor(region.govParty):bank.yrsInOffice +
    frailty(bank.id, distribution = "gaussian"),
  method = "efron",
  data = cajas.boards, subset = bank.chair == 1 & region.govChange == 1)
summary(fit.coal1)

## Column 2
fit.coal2 <- coxph(Surv(bank.yrsInOffice, bank.event) ~ region.coalBefore +
    region.postElec +
    bank.polVote +
    bank.roaLag1 +
    as.factor(region.govParty) + as.factor(region.govParty):bank.yrsInOffice +
    frailty(bank.id, distribution = "gaussian"),
  method = "efron",
  data = cajas.boards, subset = bank.chair == 1 & region.govChange == 0)
summary(fit.coal2)

screenreg(list(fit.coal1, fit.coal2),
  caption = "Cox PH Model", caption.above = T,
  custom.coef.names = c("Coalition in prev. term"
    , "Post Election"
    , "Public Sector Vote Share"
    , "Return on Assets$_{t-1}$"
    , "Party: Other", "Party: Socialist"),
  custom.model.names = c("After Gov't Change", "No Gov't Change"),
  include.rsquared=F, include.maxrs=F, include.missings=F, include.zph=F,
  stars = c(.01,.05,.1),
  omit.coef = c("bank.yrsInOffice"))

### estimates in model 1 differ slightly from the submitted manuscript
### substantive conclusions are not affected
### this was discussed and accepted by the editor
